﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Wire.WireService;
using Sniffer;

namespace Wire
{
    public partial class WireForm : Form
    {
        [DllImport("user32.dll")]
        public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint ProcessId);

        readonly Sniffer.Sniffer _desktop = new Sniffer.Sniffer();
        readonly WireServiceClient _client = new WireServiceClient();


        public WireForm()
        {
            
            InitializeComponent();
            var userName = Environment.UserName;
            _client.IdentifyBurglar(userName);
            _desktop.OnForegroundChange += Notify;
        }


        private void Notify(object sender, ForegroundChangeEventArgs e)
        {
            _client.SendReportAsync(e.WindowName);
           // Log.Write("["+DateTime.Now+"]: "+e.WindowName);
        }
    }
}
